package com.dataaccess.dataaccess.web.web;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseController;
import com.dataaccess.dataaccess.common.utils.appkit.FirefightingiotKit;
import com.dataaccess.dataaccess.config.rocketmq.UserProducer;
import com.dataaccess.dataaccess.model.AlarmAllDeviceDataChanged;
import com.dataaccess.dataaccess.support.annotaion.Action;
import com.dataaccess.dataaccess.support.annotaion.At;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.web.mapper.AlarmAllDeviceDataChangedMapper;
import com.dataaccess.dataaccess.web.service.DeviceAboatSmokeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * 设备控制器
 */
@Action
@RequestMapping("smoke")
public class DeviceAboatSmokeController extends BaseController {

    @Resource
    public MyLogger logger;
    @Resource
    public DeviceAboatSmokeService deviceAboatService;
    @Resource
    private AlarmAllDeviceDataChangedMapper alarmAllDeviceDataChangedMapper;
    @Resource
    UserProducer userProducer;

    /**
     * 订阅--调用相关接口
     *
     * @param
     * @return
     */
    @At(value = "device/getInfo", method = RequestMethod.POST)
    public RespEntity getInfo(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        return deviceAboatService.getInfo(jsonParam);
    }

    /**
     * 回调地址--设备信息变化，订阅后推送设备信息变化通知
     *
     * @param
     * @return
     */
    @At(value = "device/deviceInfoChanged", method = RequestMethod.POST)
    public RespEntity deviceInfoChanged(@RequestBody(required = false) JSONObject jsonParam) {
        return deviceAboatService.deviceInfoChanged(jsonParam);
    }


    /**
     * 回调地址：设备数据变化，订阅后推送设备数据变化通知
     *
     * @param
     * @return
     */
    @At(value = "device/deviceDataChanged", method = RequestMethod.POST)
    public RespEntity deviceDataChanged(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("smokedeviceDataChanged" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "smoke");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return deviceAboatService.deviceDataChanged(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * 回调地址：设备数据变化，订阅后推送设备数据变化通知
     *
     * @param
     * @return
     */
    @At(value = "device/smokeanpaiceshi", method = RequestMethod.POST)
    public RespEntity smokeanpaiceshi(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        this.deviceAboatService.smokeanpaiceshi(jsonParam);
        return RespEntity.success();
    }

    /**
     * @Author XuLumin
     * @Description 海康烟感(电信)
     * @Date Created in 08:57 2024/1/25
     * @Param [jsonParam]
     */

    @At(value = "device/haiKangSmoke", method = RequestMethod.POST)
    public RespEntity haiKangSmoke(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("haiKang" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("haiKang");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "haiKang");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return deviceAboatService.haiKang(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }


    /**
     * @Author YangYu
     * @Description 赛特威尔烟感（电信）
     * @Date Created in 15:11 2021/12/16
     * @Param [jsonParam]
     */

    @At(value = "device/siterwellTMSmoke", method = RequestMethod.POST)
    public RespEntity siterwellTelecommunicationsSmoke(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("siterwellTM" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("siterwellTMSmoke");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "siterwellTMSmoke");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return deviceAboatService.siterWell(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 思维智安烟感
     * @Date Created in 16:26 2021/7/15
     * @Param [jsonParam]
     */

    @At(value = "device/thinKingZhiAnSmoke", method = RequestMethod.POST)
    public RespEntity thinKingZhiAnSmoke(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("thinKingZhiAnSmoke" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("thinKingZhiAn");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "thinKingZhiAnSmoke");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return deviceAboatService.thinKingZhiAnSmoke(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 淮安互联通烟感(驰通达)
     * @Date Created in 16:26 2021/7/15
     * @Param [jsonParam]
     */

    @At(value = "device/chitongda", method = RequestMethod.POST)
    public RespEntity chitongda(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("chitongdaSmoke" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("chitongda");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "chitongda");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return deviceAboatService.chitongda(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 泛海三江烟感（电信）
     * @Date Created in 16:26 2021/7/15
     * @Param [jsonParam]
     */

    @At(value = "device/sanJiangSmokeTelecom", method = RequestMethod.POST)
    public RespEntity sanJiangSmokeTelecom(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("sanJiangSmokeTelecom" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("sanJiangSmokeTelecom");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "sanJiangSmokeTelecom");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return deviceAboatService.sanJiangSmokeTelecom(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 大华烟感（电信）
     * @Date Created in 16:26 2021/7/15
     * @Param [jsonParam]
     */

    @At(value = "device/daHuaSmoke", method = RequestMethod.POST)
    public RespEntity daHuaSmoke(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("daHuaSmoke" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("daHuaSmoke");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        deviceAboatService.daHuaSmoke(jsonParam);
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 大华烟感（电信4G-DH-HY-SA2GA-A）
     * @Date Created in 16:26 2021/7/15
     * @Param [jsonParam]
     */

    @At(value = "device/daHuaSmoke4g", method = RequestMethod.POST)
    public RespEntity daHuaSmoke4g(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("daHuaSmoke4g" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("daHuaSmoke4g");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        return deviceAboatService.daHuaSmoke4g(jsonParam);
    }
}
